package cn.wk.servlet;

import cn.wk.services.ScoreServices;
import cn.wk.services.impl.ScoreServicesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/scoreeditmdiff")
public class Servletscoreeditmdiff extends HttpServlet {
    private static ScoreServices ss=new ScoreServicesImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String[] sids = request.getParameterValues("sid");
        String[] subjects = request.getParameterValues("subject");
        boolean flag=false;
        for (int i = 0; i < sids.length; i++) {
            int b = ss.MdiffScore(Integer.parseInt(subjects[i]),Integer.parseInt(sids[i]));
            if(b>0)
                flag=true;
            else{
                flag=false;
                break;
            }
        }

        if(flag){
            request.setAttribute("ok","成绩添加成功！");
            request.getRequestDispatcher("/scoreeidt.jsp").forward(request,response);
        }else {
            request.setAttribute("error","成绩添加失败！");
            request.getRequestDispatcher("/scoreeidt.jsp").forward(request,response);
        }




    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
